<template>
  <div>
    <el-dialog title="导入" :visible.sync="dialogVisible" width="200" :close-on-click-modal="false">
      <el-button type="primary" @click="downTemplate">下载模板</el-button>
      <el-input type="file" name="file" @change="getFile"></el-input>
      <el-button type="primary" v-throttle=" [save]">保存</el-button>
    </el-dialog>
  </div>
</template>

<script>
import { downloadBlob } from "@/utils";
import { download } from "@/admin/api/common";
import { receivableImport } from '../../../api/finance-collection-receivable'
import uploadMedia from '@/components/upload-media'
export default {
  name: "lead-data",
  components: { uploadMedia },
  data () {
    return {
      dialogVisible: false,
      leadFile: null,
    }
  },
  methods: {
    show () {
      this.dialogVisible = true
    },
    //下载模板
    downTemplate () {
      var url = '/api/financecollectionreceivable/downTemplate'
      download(url, {}).then(res => {
        downloadBlob(res.data, '导入模板.xlsx')
      })
    },
    getFile (event) {
      this.leadFile = event.target.files[0];
    },
    save () {
      let formData = new FormData();
      formData.append('leadFile', this.leadFile);
      receivableImport(formData).then(res => {
        if (res.data.code == 0) {
          this.$alert("提交成功");
          this.dialogVisible = false
          this.$emit("resetList")
        } else {
          this.$alert("服务端异常：" + response.message);
        }
      })
    }
  }
}
</script>

